package day2.pet;

import java.util.Objects;

/**
 * @author oldliu
 * @since 1.0
 */
public /*final*/ class Dog extends Pet implements Comparable<Dog> {
    private String strain;//类别
    public Dog(String name, String sex, int health, int love) {
        super(name, sex, health, love);
         // System.out.println("狗的构造方法结束");
    }
    public Dog(String name, String sex, int health, int love,String s) {
        super(name, sex, health, love);
        this.strain=s;

    }
    public String getStrain() {
        return strain;
    }

    public void setStrain(String strain) {
        this.strain = strain;
    }
    //加一个方法
    public void catchMouse(){
        System.out.println(getName()+"正在抓老鼠！");
    }

    @Override//重写父类的方法
    public final void eat() {
        //super.eat();
        System.out.println(super.getName()+"在吃狗粮！");
    }

    @Override
    public  void print() {
        super.print();
        System.out.println("类别是"+strain);
    }

    @Override
    public String toString() {
        return super.toString()+",类别是："+strain;
    }
    //定标准

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dog dog = (Dog) o;
        return Objects.equals(getName(), dog.getName());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getName());
    }

    //
    @Override
    public int compareTo(Dog o) {
       //return this.getName().compareTo(o.getName());
        return this.getLove()-o.getLove();
        //  return (this.getHealth()+this.getLove())-(o.getHealth()+o.getLove());
    }

//    @Override
//    public boolean equals(Object obj) {
//        //obj把变成Dog
//        if(obj instanceof Dog){//obj其实是个Dog类的对象
//            Dog t=(Dog)obj;//强转！
//            if(this.name==null &&t.name==null)
//                return true;
//            else if(this.name==null){
//                return false;
//            }
//            return this.name.equals(t.name);//名字相同，就是相等
//        }
//        return false;
//    }
//
//    @Override
//    public int hashCode() {
//        String n=super.getName();
//        return n==null?0:n.hashCode();
//    }
}
